import { useUserStore } from '@renderer/store'

const TOKEN_KEY = 'token'

const isLogin = () => {
  return !!localStorage.getItem(TOKEN_KEY)
}

const getToken = () => {
  return localStorage.getItem(TOKEN_KEY)
}

const setToken = (token: string) => {
  localStorage.setItem(TOKEN_KEY, token)
}

const clearToken = () => {
  localStorage.removeItem(TOKEN_KEY)
}

// 权限校验
const isAuth = (role: number[]) => {
  const userInfo = useUserStore().localUserInfo
  return role.includes(userInfo.isAdmin)
}

export { isLogin, getToken, setToken, clearToken, isAuth }
